//
//  StoreViewController.m
//  New
//
//  Created by dlios on 15-7-23.
//  Copyright (c) 2015年 yangTao. All rights reserved.
//

#import "StoreViewController.h"


@interface StoreViewController ()

@end

@implementation StoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhuijian.png"] style:UIBarButtonItemStylePlain target:self action:@selector(ButtonAction)];
    self.navigationItem.leftBarButtonItem = button;
    self.navigationItem.title =@"收藏详情";
    [[playDataBase sharPlayDataBase]OpenDB];
  
    self.tabV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-22-44-49) style:UITableViewStylePlain];
    self.tabV.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tabV];
    self.tabV.delegate= self;
    self.tabV.dataSource = self;
    self.tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
 
 
    
    // Do any additional setup after loading the view.
}




-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [[playDataBase sharPlayDataBase]selectAllStore].count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *ident = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
    }
    BaseUiview *view = [[BaseUiview alloc]initWithFrame:CGRectMake(0, 87, WIDTH, 1)];
    [cell addSubview:view];
    cell.backgroundColor = [UIColor clearColor];
    BaseLabel *label = [[BaseLabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 88)];
//    label.numberOfLines = 0;
    PlayModel *playMod = [[[playDataBase sharPlayDataBase]selectAllStore] objectAtIndex:indexPath.row];
//    label.text =playMod.contentHtml;
    [cell addSubview:label];
    
    UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 88)];//初始化UIWebView
    [label addSubview:myWebView];
    
    NSString *htmlString = playMod.contentHtml;//设置UIWebView的内容
    
    [myWebView loadHTMLString:htmlString baseURL:nil];//加载内容
    myWebView.dataDetectorTypes = UIDataDetectorTypeNone;
    
//    myWebView.scalesPageToFit = YES;
    myWebView.backgroundColor = [UIColor lightGrayColor];
    myWebView.opaque = NO;

    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 90;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

    return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    if (editingStyle == UITableViewCellEditingStyleDelete) {
          PlayModel *playMod = [[[playDataBase sharPlayDataBase]selectAllStore] objectAtIndex:indexPath.row];
        [[playDataBase sharPlayDataBase]dropTable1:playMod];

    
        [self.tabV reloadData];
        
    }

}
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除 ";
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    PlayDetailViewController *playDvc = [[PlayDetailViewController alloc]init];
     PlayModel *playMod = [[[playDataBase sharPlayDataBase]selectAllStore] objectAtIndex:indexPath.row];
    playDvc.ID =playMod.ID;

    [self.navigationController pushViewController:playDvc animated:YES];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
   
    [self.tabV reloadData];
    
}

-(void)ButtonAction{

    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
